layui.config({
	base : "js/"
}).use(['form','layer','jquery','layedit','laydate'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		layedit = layui.layedit,
		laydate = layui.laydate,
		$ = layui.jquery;

	//创建一个编辑器
 	var editIndex = layedit.build('news_content');
 	var addNewsArray = [],addNews;
 	form.on("submit(subInfo)",function(data){
		layedit.sync(editIndex);
 		
 		var data={
 			name:$(".orgName").val(),
 			mark:$(".orgMark").val(),
 			type:$('input:radio[name="otype"]:checked').val(),
 			officeSite:$(".orgAddr").val(),
 			officeTel:$(".orgTel").val(),
 			tenureTime:$(".tenureTime").val(),
 			introduce:$("#news_content").val()
 		}
 		var index = layer.load(1, {shade: [0.1, '#fff']}); //0.1透明度的白色背景
 		
		addInfo(data,function(){
			layer.close(index);
				//top.layer.close(index);
				top.layer.msg("组织信息添加完成！");
				layer.closeAll("iframe");
				//刷新父页面
				parent.location.reload();
		});
 		return false;
 	})
})

function addInfo(data, callback) {
		$.ajax({
			url: $.httpRootPath() + '/api/web/organize/add',
			type: 'POST',
			dataType: 'json',
			data: data,
			timeout: 15000,
			cache: false,
			success: function(r) {
				if(r.code == "00") {
					layer.msg("新增成功！");
				} else {
					layer.msg("新增失败！"+r.msg);
				}
			},
			error: function(e) {
				layer.msg("系统错误！");
			},
			complete: function() {
				setTimeout(function(){
					callback()
				},1500);
			}
		});

}
function checkMark(data,callback){
	var index1 = layer.load(1, {shade: [0.1, '#fff']}); //0.1透明度的白色背景
	var data = {
		mark:data.mark
	}
	 $.ajax({
        url: $.httpRootPath()+"/api/web/organize/check-mark",
        type: 'GET',
        dataType: 'json',
        data: data,
        timeout: 15000,
        cache: false,
        success: function (r) {
            if (r.code != "00") {
              	layer.msg("标识符已被占用,请重新填写！");
                return;
            }else{
            	 callback();
            }
        },
        error: function (e) {
          layer.msg("系统错误！");
        }
    });
}
